-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-115957: Close coroutine if the TaskGroup is inactive #116009
Conversation
e4ab02f
to
6a0265d
Compare
Thanks for doing this! I was dangerously close to doing it myself even though I really don't have time, just for the kudos of being a "Python contributor", so I'm really glad you did 😄 My comments:
|
Thanks for the comments Arthur! Yeah that makes sense, I will update the wording there. Regarding the test, it raises a RuntimeWarning without the change for me. Maybe we have slightly different configs? But yeah let me try more specifically sending on the coroutine as well. Thanks again! |
Sorry, to be honest I haven't actually run the tests (or for that matter cloned the CPython repo at all), I was just reading the test code. If the test suite automatically fails if there's a warning then you can ignore that comment. |
7f28db0
to
8e9866e
Compare
Sorry for tagging but a gentle nudge for reviewing please 🙏 @gvanrossum |
Yeah, it's in my queue. |
Got it, thank you 🙏 |
542d7c2
to
e7c3a5e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the tests you changed and added still pass even if I comment out the three coro.close()
calls added to taskgroups.py. While they print the RuntimeWarning message, they don't fail. Could you try to detect the warnings in at least one of the tests?
Doc/library/asyncio-task.rst
Outdated
.. versionchanged:: 3.13 | ||
|
||
Close the given coroutine if the task group is not active. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that the convention is that a description of the new/changed behavior is added to the main text of the documentation (in this case the two lines right above) and then the versionchanged
directive is used to clarify when this behavior was added or changed. In this case that would be a little redundant but I still feel it's appropriate.
For example, the main text could include information about when a task group is considered inactive (e.g. not yet entered, already finished, or in the process of shutting down).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation! I've updated the main text
Doc/whatsnew/3.13.rst
Outdated
@@ -185,6 +185,11 @@ Other Language Changes | |||
|
|||
(Contributed by Sebastian Pipping in :gh:`115623`.) | |||
|
|||
* When :func:`asyncio.TaskGroup.create_task` is called on an inactive | |||
:class:`asyncio.TaskGroup`, the given coroutine will be closed (which | |||
prevents a :exc:`RuntimeWarning`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd clarify that the RuntimeWarning is about "coroutine 'blank' was never awaited".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the comments! I've updated the wording
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
22d94f3
to
5d0d518
Compare
Thanks for the detailed explanations @gvanrossum ! I have updated one of the tests so that it now explicitly captures and asserts no warning. I've tried it on my machine (MacOS) and it is now failing without the change. Please let me know if there is any other improvement I can apply. Thanks! I have made the requested changes; please review again |
Thanks for making the requested changes! @gvanrossum: please review the changes made to this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good! The tests pass in CI, one of the tests fails if I undo the changes in taskgroups.py only, so I will merge.
PS. Next time please don't force push. We squash changes when we merge into main anyway, and the force push makes it harder to re-review the code. |
Thanks @gvanrossum for the review and for the note! I will remember not to force push next time 👌 |
This PR addresses the issue where when we call
TaskGroup.create_task()
with an inactiveTaskGroup
, we still get aRuntimeWarning
for the coroutine. This change makes sure that the coroutine is closed in this case and updated the tests accordingly.📚 Documentation preview 📚: https://cpython-previews--116009.org.readthedocs.build/